package logic

import (
	"context"
	"novel/model/mysql"
	"novel/novelrpc/internal/svc"
	"novel/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCourseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseListLogic {
	return &CourseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CourseListLogic) CourseList(in *novelrpc.CourseListRequest) (*novelrpc.CourseListResponse, error) {
	// todo: add your logic here and delete this line

	var course []mysql.Course
	mysql.DB.Debug().
		//Model(&mysql.Course{}).
		//Select("courses.*, novels.id as novel_id").
		//Joins("left join courses on courses.novel_id = novel_id").
		Find(&course)

	var user []*novelrpc.CourseList

	for _, data := range course {
		list := novelrpc.CourseList{
			UserId:  int64(data.UserId),
			NovelId: int64(data.NovelId),
			Ifor:    data.Ifor,
		}
		user = append(user, &list)

	}
	return &novelrpc.CourseListResponse{
		List: user,
	}, nil
}
